package com.softmaker.service;

import com.softmaker.entity.UserTask;
import com.softmaker.repository.UserTaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.UUID;

@Service
public class UserTaskService {
    @Autowired
    private UserTaskRepository repository;
    public UserTask addUserTask(UserTask userTask) {
        userTask.setId(UUID.randomUUID().toString());
        return repository.save(userTask);

    }
    public UserTask findUserTask(String userName,String taskName) {
        return repository.findUserTaskByUserNameAndTaskName(userName,taskName);
    }
    @Transactional
    public void deleteByUserNameAndTaskId(String userId,String taskName) {
        repository.deleteByUserNameAndTaskName(userId,taskName);
    }
    @Transactional
    public UserTask updateStatCountByUserIdAndTaskId(UserTask userTask){
//       return repository.updateStateByUserIdAndTaskId(stateCount,userId,taskId);
        return repository.save(userTask);
    }
    public List<UserTask> findAll(){
        return repository.findAll();
    }
}
